import * as sdk from './fetch';

/**
 * 游戏任务根据游戏类型
 * @param params
 * @returns
 */
async function getTasksByGameType(params = {}): Promise<any> {
  let result = await sdk.get<any>(`gametaskcustomercenter/list/${params.gameType}`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 游戏详情
 * @param params
 * @returns
 */
async function getTaskDetailById(params = {}): Promise<any> {
  let result = await sdk.get<any>(`gametaskcustomercenter/${params.id}`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 完成任务
 * @param params
 * @returns
 */
async function computedTask(params = {}): Promise<any> {
  let result = {
    context: '',
    code: '',
    message: '',
  };
  try {
    result = await sdk.post<any>(`gametaskcustomercenter/completedTask`, {
      ...params,
    });
  } catch (e) {
    result = e;
  }
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

export default {
  getTasksByGameType,
  getTaskDetailById,
  computedTask,
};
